// pages/store/print/photo/photo.js
Page({

  data: {fileList: [],list:[],goods_id:'',url1:'',value:1,speclist:[],a:'3',b:'5',c:'14',tijiao_id:"",tempFilePaths:''
  
  },

  onLoad: function (options) {
    this.setData({
      goods_id:options.id
    })
    this.getrulelist()
  
  },
   //单选框纸张大小
   onchange(e){
    console.log(e);
    var that=this
    console.log(that.data.speclist);
    
      
       if(e.currentTarget.dataset.index==0){
          that.setData({
             a:e.detail.value
          })
          
       }else{
         if(e.currentTarget.dataset.index==1){
           that.setData({
             b:e.detail.value
           })
         }else{that.setData({
           c:e.detail.value
         })}
       }   
      },
      getrulelist(){
        wx.request({
          url: 'https://zujieba.com/Api/spec/spec',
          data:{id:this.data.goods_id},
          success:(res)=>{
          console.log(res);
          const speclist=res.data.data.spec
          this.setData({
            speclist
          })
          console.log(this.data.speclist);
          
          
          }
        })
      },
       //提交订单
    orderclick(){
      var that=this
      const uid=wx.getStorageSync('uid')
      const selectid=that.data.a+'_'+that.data.b+"_"+that.data.c
      console.log(selectid);
      
      const type=that.data.value
      const params={goods_id:that.data.goods_id,spec_id:selectid,uid,file:that.data.url1}
      console.log(params);
      
      wx.request({
        url: 'https://zujieba.com/Api/car/add_car.html',
        data:params,
        success:(res)=>{
          const tijiao_id=res.data.data
        that.setData({
          tijiao_id
        })
          console.log(res);
         
          if(res.data.success==2){
            wx.showToast({
              title: res.data.tips,
              icon:'none'
            })
          }else{
            wx.navigateTo({
              url: '/pages/order/order?id='+this.data.tijiao_id,
            })
          }
          
             
        }
     
      })
    },
    onchange1(e){
      this.setData({
        value:e.detail
      })
      
       
    },
    //拍照
    photoclick(){
     wx.chooseMessageFile({
           count: 1,
           complete: (res) => {
             console.log(res);
             
          this.setData({
            tempFilePaths:res.tempFiles[0].path
          })
          wx.downloadFile({
            url: '',
          })
           
     
            
          
          
          
       

           },
         })



    }
    
 })
